// @Author EthanScriptOn
// @Desc
package controller

import (
	"gitee.com/fatzeng/srf_switch_basic_components/switch_log"
	"gitee.com/fatzeng/srf_switch_dynamic_logic_director/middleware"
	"gitee.com/fatzeng/srf_switch_dynamic_logic_director/request"
	"gitee.com/fatzeng/srf_switch_dynamic_logic_director/response"
	"gitee.com/fatzeng/srf_switch_dynamic_logic_director/service"
	"github.com/gin-gonic/gin"
)

type SwitchController struct{}

func (s *SwitchController) Router(router *gin.Engine) {
	entry := router.Group("/switch_control/v1/core", middleware.IdentityVerification())
	entry.POST("/switchOptionDetailList", s.switchOptionDetailList)
	entry.POST("/switchList", s.switchList)
	entry.POST("/switchPublish", s.switchPublish)
}

func (s *SwitchController) switchOptionDetailList(ctx *gin.Context) {
	params := new(request.SwitchOptionDetailRequest)
	err := ctx.ShouldBind(params)
	if err != nil {
		switch_log.Logger().Error("SwitchController/switchOptionDetailList", err)
		ctx.JSON(200, response.GenerateCurrencyResponse(nil, response.Fail))
		return
	}
	list, err := service.GetSwitchOptionDetail(params)
	if err != nil {
		switch_log.Logger().Error("SwitchController/switchOptionDetailList", err)
		ctx.JSON(200, response.GenerateCurrencyResponse(nil, response.Fail))
		return
	}
	ctx.JSON(200, response.GenerateCurrencyResponse(list, response.Success))
}

func (s *SwitchController) switchList(ctx *gin.Context) {
	params := new(request.SwitchListRequest)
	err := ctx.ShouldBind(params)
	if err != nil {
		switch_log.Logger().Error("SwitchController/switchList", err)
		ctx.JSON(200, response.GenerateCurrencyResponse(nil, response.Fail))
		return
	}
	list, err := service.GetSwitchList(params)
	if err != nil {
		switch_log.Logger().Error("SwitchController/switchList", err)
		ctx.JSON(200, response.GenerateCurrencyResponse(nil, response.Fail))
		return
	}
	ctx.JSON(200, response.GenerateCurrencyResponse(list, response.Success))
}

func (s *SwitchController) switchPublish(ctx *gin.Context) {
	params := new(request.SwitchContentRequest)
	err := ctx.ShouldBind(params)
	if err != nil {
		switch_log.Logger().Error("SwitchController/switchPublish", err)
		ctx.JSON(200, response.GenerateCurrencyResponse(nil, response.Fail))
		return
	}
	err = service.PublishSwitch(ctx, params)
	if err != nil {
		switch_log.Logger().Error("SwitchController/switchPublish", err)
		ctx.JSON(200, response.GenerateCurrencyResponse(nil, response.Fail))
		return
	}
	ctx.JSON(200, response.GenerateCurrencyResponse(nil, response.Success))
}
